home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / QuickDraw / Restore Screen Cluts / Exceptions.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  3.4 KB  |  91 lines  |  [TEXT/MPS ]

  1. #ifndef __EXCEPTIONS__
  2. #define __EXCEPTIONS__
  3. /******************************************************************************\
  4. *
  5. * Apple Macintosh Developer Technical Support
  6. *
  7. * Exception-handling routines
  8. *
  9. * Program: ColorReset
  10. * File:    Exception.h
  11. *
  12. * by:      Forrest Tanaka
  13. *
  14. * Copyright © 1988-1991 Apple Computer, Inc.
  15. * All rights reserved.
  16. *    
  17. \******************************************************************************/
  18.  
  19.  
  20. /******************************************************************************\
  21. * Types
  22. \******************************************************************************/
  23.  
  24. typedef struct
  25.     {
  26.     long          *exceptionType; /* Pointer to type of exception */
  27.     short         *exceptionCode; /* Pointer to code number of exception */
  28.     unsigned long registers [12]; /* Holds saved values of registers, PC, SP */
  29.     } ExceptionRec, *ExceptionPtr;
  30.  
  31.  
  32. /******************************************************************************\
  33. * ExceptionEntry - Define variables and location of exception-handling code
  34. *
  35. * This is an especially odd function in that when a routine calls this function,
  36. * it’s actually defining a location that the flow of control should jump to if
  37. * the Exception function is called later in the same routine.  The calls should
  38. * be made like this:
  39. *
  40. * ExceptionRec environment;
  41. * long exceptionType;
  42. * long exceptionCode;
  43. * long errorType;
  44. * long errorCode;
  45. *
  46. * if (ExceptionEntry (&environment, &exceptionType, &exceptionCode))
  47. *     {
  48. *     Clean-up statements here;
  49. *     Maybe present error message to user here;
  50. *     return;
  51. *     }
  52. * Normal statements here;
  53. * if (errorHasHappened)
  54. *     Exception (&environment, errorType, errorCode);
  55. * Normal function statements here;
  56. *
  57. * The first time ExceptionEntry is called in a routine, it’s guaranteed to
  58. * return 0.  The clean-up statements are skipped in this case.  The flow of
  59. * control then proceeds to the normal program statements.  If an error occurs
  60. * and Exception is called, then the flow of control suddenly jumps back to the
  61. * ExceptionEntry call.  This time, -1 is returned, and exceptionType and
  62. * exceptionCode return whatever values were passed in the Exception call. At
  63. * this time, the routine should clean up anything it allocated, possibly present
  64. * an error message to the user, then return to the calling routine.
  65. \******************************************************************************/
  66.  
  67. extern short ExceptionEntry(ExceptionPtr environment,
  68.                             long         *exceptionType,
  69.                             long         *exceptionCode);
  70.  
  71.  
  72. /******************************************************************************\
  73. * Exception - Signal that an exception has occured
  74. *
  75. * When an error occurs, Exception is called to pass control to the set of
  76. * statements that execute when ExceptionEntry returns true.  The environment
  77. * parameter specifies the same record that was passed to ExceptionEntry.  If
  78. * it specifies a different record, then unpredictable things can happen.  The
  79. * exceptionType and exceptionCode parameters specify values to be returned in
  80. * the corresponding parameters to ExceptionEntry.  In this application they’re
  81. * normally used to pass the type of error and the code of the specific error
  82. * that occured.
  83. \******************************************************************************/
  84.  
  85. extern void Exception(ExceptionPtr environment,
  86.                       long         exceptionType,
  87.                       long         exceptionCode);
  88.  
  89.  
  90. #endif
  91.